package p200;

import java.util.Arrays;

public class Leetcode_204 {
    /**
     * 厄拉多塞筛法
     */
    public int countPrimes(int n) {
        int[] num = new int[n];
        for (int i = 2; i < n; i++) {
            num[i] = i;
        }
        for (int i = 2; i < n; i++) {
            if (0 != num[i]) {
                for (int j = 2; j * i < n; j++) {
                    num[j * i] = 0;
                }
            }
        }
        Arrays.stream(num).filter(v -> v > 0).forEach(System.out::println);
        return (int) Arrays.stream(num).filter(v -> v > 0).count();
    }

    public static void main(String[] args) {
        Leetcode_204 l = new Leetcode_204();
        System.out.println(l.countPrimes(10));
    }
}
